package com.heny.demo.util;

import com.heny.demo.entity.PointData;
import com.heny.demo.entity.TurnPoint;
import org.locationtech.jts.geom.GeometryFactory;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yaonn
 * @date 2025/9/1122:36
 * @Description
 */
@Component
public class CsvImportStrategy implements FileImportStrategy{

    @Override
    public List<PointData> importData(InputStream inputStream) throws Exception {
        List<PointData> result = new ArrayList<>();

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            String line;
            boolean isFirstLine = true;

            while ((line = reader.readLine()) != null) {
                if (isFirstLine) {
                    isFirstLine = false;
                    continue; // 跳过标题行
                }

                String[] data = line.split(",");
                if (data.length >= 4) {
                    String name = data[0].trim();
                    double x = Double.parseDouble(data[1].trim());
                    double y = Double.parseDouble(data[2].trim());
                    double z = Double.parseDouble(data[3].trim());

                    result.add(new PointData(name, x, y, z));
                }
            }
        }
        return result;
    }

    @Override
    public boolean supports(String fileType) {
        return "csv".equalsIgnoreCase(fileType);
    }
}
